#!/usr/bin/env python
from operator import itemgetter
import sys
industry_count_dict={}
word = None
# input comes from STDIN
for line in sys.stdin:
    # remove leading and trailing whitespace
    line = line.strip()

    # parse the input we got from mapper.py
    word, count = line.split('\t', 1)
 
    # convert count (currently a string) to int
    try:
        count = int(count)
        industry_count_dict[word]=industry_count_dict.get(word,0)+count
    except ValueError:
        # count was not a number, so silently
        # ignore/discard this line
        continue
sorted_industry_count_list=sorted(industry_count_dict.iteritems(),key=lambda d:d[1],reverse=True)
for industry_count_tuple in sorted_industry_count_list:
    print industry_count_tuple[0]+"\t"+str(industry_count_tuple[1])

